package logic

import (
	"context"

	"go-zero-demo-04/mall/quiz/api/internal/svc"
	"go-zero-demo-04/mall/quiz/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetQuizLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetQuizLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetQuizLogic {
	return &GetQuizLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetQuizLogic) GetQuiz(req *types.QuizRequest) (resp *types.QuizResponse, err error) {
	res, err := l.svcCtx.QuizModel.FindOne(l.ctx, req.QuizID)
	if err != err {
		return nil, err
	}

	return &types.QuizResponse{
		QuizID:       res.TestNum,
		QuizDescribe: res.TestDescribe,
		QuizOption_A: res.TestOptionA,
		QuizOption_B: res.TestOptionB,
		A_answer:     res.AAnswer,
		B_answer:     res.BAnswer,
	}, nil
}
